/**
 * Created by lins on 2018-7-17.
 */
angular.module('MetronicApp').controller('SourceAnalysisListController',
    ['$rootScope', '$scope', '$state', '$stateParams', '$uibModal', 'toastr', 'EnumService', 'SourceAnalysisService',
        function ($rootScope, $scope, $state, $stateParams, $uibModal, toastr, EnumService, SourceAnalysisService) {
            $scope.$on('$viewContentLoaded', function () {
                App.initAjax();
                $rootScope.settings.layout.pageBodySolid = true;
                $rootScope.settings.layout.pageSidebarClosed = false;
            });

            $scope.condition = {};
            $scope.range = EnumService.get("area");

            $scope.tabItemList = [
                {
                    "name": "污染源分析",
                    "router": "sourceAnalysisList",
                    "selected": true
                },
                {
                    "name": "周期性分析",
                    "router": "periodicAnalysisList",
                    "selected": false
                },
                {
                    "name": "案例分析",
                    "router": "caseAnalysisList",
                    "selected": false
                },
                {
                    "name": "传输影响分析",
                    "router": "pollutantSourceList",
                    "selected": false
                }
            ]

            $scope.list = function () {
                SourceAnalysisService.putSearchParams({
                    search: $scope.condition.search
                });
                SourceAnalysisService.list(function (res) {
                    if ('success' === res.status) {
                        $scope.rows = res.data;
                        $scope.pageable = res.pageable;
                    } else {
                        for (var i = 0; i < res.errors.length; i++) {
                            toastr.error(res.errors[i].errmsg, "数据获取失败");
                        }
                    }
                });
            };


            var gotoFirstPage = function () {
                SourceAnalysisService.setStoredPage(0);
                $scope.list();
                SourceAnalysisService.clearSearchParams();
            };
            gotoFirstPage();

            //查询
            $scope.search = function () {
                gotoFirstPage();
            };
            // 配置
            $scope.deploy = function () {
                $state.go('deployManagement');
            };



        }
    ]
);